package org.budo.validation.exception;

import org.hibernate.validator.constraints.Length;

/**
 * @author lmw
 */
public class BudoLengthValidationException extends AbstractBudoValidationException {
    private static final long serialVersionUID = 4969260450165845737L;

    private static final String MESSAGE_DEFAULT = "{org.hibernate.validator.constraints.Length.message}";

    public BudoLengthValidationException(Integer parameterIndex, String parameterName, Length annotation, Object parameterValue) {
        super(parameterIndex, parameterName, annotation, parameterValue, validationMessage(annotation.message(), MESSAGE_DEFAULT));
    }

    @Override
    protected String buildMessage() {
        Length length = (Length) this.getAnnotation();
        return "parameter[" + this.getParameterIndex() + "] " + this.getParameterName() + " length " + this.getParameterValue() //
                + " is not in [" + length.min() + ", " + length.max() + "]";
    }
}